/*
 * demo1.cpp
 *
 *  Created on: 2012-8-20
 *      Author: huangyansheng
 */

#include <gtest/gtest.h>
//计算商品总价
int total_4(int price,int number)
{
	if(price<0)
		return -1;
	else if(number<0)
		return -1;
	else
		return price*number;
}

TEST(total_4,price1){
	EXPECT_EQ(10,total_4(1,10));
	EXPECT_EQ(10,total_4(2,5));
	EXPECT_EQ(10,total_4(5,2));
	EXPECT_EQ(10,total_4(10,1));
}
TEST(total_4,price_zero){
	EXPECT_EQ(0,total_4(0,10));
	EXPECT_EQ(0,total_4(10,0));
}
TEST(total_4,price_negative){
	EXPECT_EQ(-1,total_4(-1,10));
	EXPECT_EQ(-1,total_4(10,-1));
	EXPECT_EQ(-1,total_4(-10,-1));
}

class Total_param {
public:
	int a;
	int b;
	Total_param(int aa,int bb)
	{
		a=aa;
		b=bb;
	}
};
class total_4_p : public::testing::TestWithParam<Total_param>
{

};
TEST_P(total_4_p,price_p){
	Total_param n = (Total_param)GetParam();
	EXPECT_EQ(10,total_4(n.a,n.b));
}
Total_param t1(1,10);
Total_param t2(2.5,4);
Total_param t3(2,5);
Total_param t4(5,2);
Total_param t5(10,1);

INSTANTIATE_TEST_CASE_P(p,total_4_p,::testing::Values(t1,t2,t3,t4,t5));

